package org.javaz.ports;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;

/**
 */
public class PortVersionInfo
{
	private String name;
	private String version;
	private String portDir;
	private ArrayList requiredBy = new ArrayList();
	private ArrayList requiredSelf = new ArrayList();


	public PortVersionInfo()
	{
	}

	public static String parse(String fullName, boolean isName)
	{
		StringBuffer sbName = new StringBuffer();
		StringBuffer sbVersion = new StringBuffer();
		boolean dashFound = false;
		boolean verB = false;
		for (int i = 0; i < fullName.length(); i++)
		{
			char c = fullName.charAt(i);
			if (c == '-')
			{
				dashFound = true;
			}

			if (!verB && dashFound && !Character.isDigit(c) && c != '-')
			{
				dashFound = false;
			}

			if (!verB && dashFound && Character.isDigit(c))
			{
				verB = true;
			}

			if (!verB)
			{
				sbName.append(c);
			}
			else
			{
				sbVersion.append(c);
			}
		}

		if (isName)
		{
			String name = sbName.toString();
			if (name.endsWith("-"))
			{
				name = name.substring(0, name.length() - 1);
			}
			return name;
		}

		String version = sbVersion.toString();
		if (version.startsWith("-"))
		{
			version = version.substring(1);
		}

		return version;
	}

	public PortVersionInfo(String fullName)
	{
		name = parse(fullName, true);
		version = parse(fullName, false);
	}

	public PortVersionInfo(String name, String version)
	{
		this.name = name;
		this.version = version;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getVersion()
	{
		return version;
	}

	public void setVersion(String version)
	{
		this.version = version;
	}

	public ArrayList getRequiredBy()
	{
		return requiredBy;
	}

	public void setRequiredBy(ArrayList requiredBy)
	{
		this.requiredBy = requiredBy;
	}

	public ArrayList getRequiredSelf()
	{
		return requiredSelf;
	}

	public void setRequiredSelf(ArrayList requiredSelf)
	{
		this.requiredSelf = requiredSelf;
	}


	public String getPortDir()
	{
		return portDir;
	}

	public void setPortDir(String portDir)
	{
		this.portDir = portDir;
	}
}
